package com.atguigu.common.config.exception;

import com.atguigu.result.Result;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    //全局异常处理执行的方法
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handler(Exception e) {
        e.printStackTrace();

        return Result.fail().message("全局异常处理");

    }

    @ExceptionHandler(MyException.class)
    @ResponseBody
    public Result handlerMy(MyException e) {
        e.printStackTrace();
        return Result.fail().message(e.toString());
    }
    @ExceptionHandler(AccessDeniedException.class)
    @ResponseBody
    public Result handlerMy(AccessDeniedException e) {
        e.printStackTrace();
        return Result.fail().message("没有权限");
    }

}
